home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / RWSUBI.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  4KB  |  140 lines

  1. ; RWSUBI - disk read/write subroutine for interpretive BASIC
  2. ; Copyright 1983 Data Base Decisions
  3. ; CALL RWSUBI(STACK$,FIL$,FCB$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
  4. ; STACK$ is a temporary stack (not needed by compiled version)
  5. ; FIL$ is the name of the file to be read or written
  6. ; FCB$ is a work area - allocate 40 spaces
  7. ; FUNC% indicates reading (0), writing (1), or creating & writing (2)
  8. ; SBYTELO% is the low part of the start byte
  9. ; SBYTEHI% is the high part of the start byte (HI*65536+LO)
  10. ; NOBYTES% is the number of bytes to be read/written
  11. ; DTASEG% is the segment to be read into or written from
  12. ; RETCODE% is the error return code
  13.  
  14. skip    equ 1            ; 2 for compiled, 1 for interpretive
  15.  
  16. cseg    segment para public 'code'
  17. public    rwsubi
  18. rwsubi    proc far
  19.     assume cs:cseg,ds:nothing,ss:nothing,es:nothing
  20.  
  21.     push bp
  22.     mov bp,sp
  23.  
  24.                 ; use passed stack
  25.     mov di,sp        ; save orig sp
  26.     mov si,[bp+22]        ; point to STACK$
  27.     mov al,[si]        ; get length
  28.     mov ah,0
  29.     add si,skip
  30.     add ax,[si]        ; add start addr
  31.     dec ax            ; down by 1
  32.     mov sp,ax        ; new sp
  33.     push di         ; save orig sp on new stack
  34.  
  35.     push ds         ; save orig ds
  36.     mov si,[bp+8]        ; point to DTASEG%
  37.     mov ax,[si]
  38.     mov ds,ax        ; now in ds
  39.     xor dx,dx        ; clear dx
  40.     mov ah,1ah
  41.     int 21h         ; set dta
  42.     pop ds            ; back to orig ds
  43.  
  44.                 ; parse FIL$ into FCB$
  45.     mov si,[bp+20]        ; point to FIL$
  46.     add si,skip
  47.     mov si,[si]
  48.     mov di,[bp+18]        ; point to FCB$
  49.     add di,skip
  50.     mov di,[di]
  51.     mov ax,2901h
  52.     int 21h         ; parse file name
  53.     cmp al,0        ; error?
  54.     jz p005         ; no
  55.     mov ah,0        ; set parse error
  56.     jmp p030
  57.  
  58. p005:                ; open the file
  59.     mov si,[bp+18]        ; point to FCB$
  60.     add si,skip
  61.     mov dx,[si]        ; fcb address
  62.     mov si,[bp+16]        ; point to FUNC%
  63.     mov al,[si]        ; get access code in al
  64.     mov ah,16h
  65.     cmp al,2        ; create?
  66.     jz p010         ; yes
  67.     mov ah,0fh        ; normal open
  68.     mov cx,0        ; clear attributes
  69. p010:    int 21h         ; open the file
  70.     cmp al,0        ; error?
  71.     jz p015         ; no
  72.     mov ah,1        ; set open error
  73.     jmp p030
  74.  
  75. p015:                ; fix up the fcb
  76.     mov si,[bp+18]        ; point to FCB$
  77.     add si,skip
  78.     mov si,[si]
  79.     mov bx,14
  80.     add bx,si        ; point to record size
  81.     mov ax,1
  82.     mov [bx],ax        ; set record size
  83.     mov bx,32
  84.     add bx,si        ; point to current record
  85.     mov [bx],ah        ; zero it
  86.     inc bx
  87.     mov si,[bp+14]        ; point to SBYTELO%
  88.     mov ax,[si]        ; get the number
  89.     mov [bx],ax        ; and save in the fcb
  90.     inc bx
  91.     inc bx
  92.     mov si,[bp+12]        ; point to SBYTEHI%
  93.     mov ax,[si]        ; get the number
  94.     mov [bx],ax        ; and save in the fcb
  95.  
  96.                 ; read/write the file
  97.     mov si,[bp+18]        ; point to FCB$
  98.     add si,skip
  99.     mov dx,[si]        ; fcb address
  100.     mov si,[bp+10]        ; point to NOBYTES%
  101.     mov cx,[si]        ; number of bytes to read/write
  102.     mov si,[bp+16]        ; point to FUNC%
  103.     mov ah,[si]        ; 0 for read, 1 for write, 2 for create
  104.     cmp ah,2        ; create?
  105.     jnz p020        ; no
  106.     dec ah            ; yes - make it a write
  107. p020:    add ah,27h        ; setup interrupt function
  108.     int 21h         ; read/write the file
  109.     mov si,[bp+10]        ; point to NOBYTES%
  110.     mov [si],cx        ; save bytes read/written
  111.     push ax         ; save errors, if any
  112.  
  113.                 ; close the file
  114.     mov ah,10h
  115.     int 21h         ; close the file
  116.     cmp al,0        ; any errors?
  117.     jz p025         ; no
  118.     pop bx            ; restore ax into bx
  119.     mov ah,3        ; indicate close error
  120.     jmp p030
  121.  
  122. p025:    pop ax
  123.     cmp al,0        ; any read/write errors?
  124.     jz p040         ; no
  125.     mov ah,2        ; indicate error type
  126.  
  127. p030:                ; error handler
  128.     mov si,[bp+6]        ; point to RETCODE%
  129.     mov [si],ax        ; save the error
  130.  
  131. p040:                ; return to caller
  132.     pop di            ; get orig sp
  133.     mov sp,di        ; back to orig stack
  134.     pop bp
  135.     ret 18
  136.  
  137. rwsubi    endp
  138. cseg    ends
  139.     end
  140.